﻿<?php require "/../00_include/01_head.php" ?>
<script type="text/javascript">var base_url = "/", edialog, ndialog;</script>
<div class='l-h-28 g-d-w  b-r-t-4 p-l-20 b-d-b-c-ddd dotum p-r'>
    <span>Home</span>
    <span class="arrow_space"></span>
    <span>Configs</span>
    <span class="arrow_space"></span>
    <span onclick="msgbox()">Language</span>
    <div class="p-a t-8 r-8 l-h-16 z-i-100">
        <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p add-icon" onclick="menu.AddItem()">Add</span>
        <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p refresh-icon" onclick="menu.Refresh()">Refresh</span>
        <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p menu-icon" onclick="accessdenied()">Menu</span>
    </div>
</div>
    <script>
        function msgbox(){
            uiMessage('Thông tin gần đây từ trang Bloomberg cho biết Microsoft...')
        }
    </script>
<div class="grid_12- p-a- t-0- l-0- b-0- b-g-c-w- z-i-1 ">
    <div id="gridview" class="frmjqxgrid p-r" style="min-height: 500px">
        <div id="jqxGrid" style="border: none;"></div>
        <div class="d-p-b h-28 b-d-t-c-ddd"></div>
        <div class="p-a b-4 l-8 l-h-16 z-i-100 p-b-2 dotum">
            <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p add-icon" onclick="menu.AddItem()">Add</span>
            <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p refresh-icon" onclick="menu.Refresh()">Refresh</span>
            <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p menu-icon" onclick="accessdenied()">Menu</span>
        </div>
    </div>
</div>
<div class="grid_12- d-p-n">
    <div id="editor_box" class="b-d-c-ccc- p-r b-g-c-w- p-4 p-l-2" style="min-height: 500px">
        <div class="p-a t-0 l-0 b-0 r-0 tranf-w-50 d-p-n" style="z-index: 1001"></div>
        <div class="p-a t-0 l-0 b-0 r-0 b-g-ldg b-g-c-w i-l-d d-p-n" style="z-index: 1002"></div>
        <div class="content-biz"></div>
        <div class="clear"></div>
    </div>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<script type="text/javascript">
    var menu=(function(){
        return{
            AddItem:function(){
                _detail('');
            },
            EditItem:function(id){
                _detail(id);
            },
            Save:function(){
                _save();
            },
            Cancel:function(){
                $('#editor_box').dialog('close');
            },
            DeleteItem:function(id){
                accessdenied();
            },
            RestoreItem:function(){
                accessdenied();
            },
            PublicItem:function(){
                accessdenied();
            },
            PrivateItem:function(){
                accessdenied();
            },
            Setting:function(){
                bckdialog({
                    message:$('#window-sOpt'),
                    icon:"<img class='p-a t-7 l-8' src='/libraries/images/16/option.gif'/>",
                    title:'Setting'
                }).open();
            },
            Refresh:function(){
                $("#jqxGrid").jqxGrid('updatebounddata');
            }
        };
    }());
    function handleEvents(){
        try{
            acolumns['_id'].cellsrenderer = function (row, column, value) {
                var str="<span style='margin: 4px; float: left;'>";
                if(value && value>0){
                    try{
                        //value = $.parseJSON(value);
                        str+="\
                            <div onclick=\"menu.EditItem('"+value+"');\" \
                            class='w-16 h-16 f-l m-r-4 c-s-p hover-50 edit-icon' title='Edit'></div>\
                        ";
                        str+="\
                            <div onclick=\"menu.DeleteItem('"+value+"');\" \
                            class='w-16 h-16 f-l m-r-4 c-s-p hover-50 del-icon' title='Delete'></div>\
                        ";

                    }catch(e){}
                }
                str+="</span>";
                return str;
            }
            acolumns['lang_key'].validation= function (cell, value) {
                if (value =="") {
                    return { result: false, message: "Keyword should be not empty." };
                }
                return true;
            };
            acolumns['lang_text'].validation= function (cell, value) {
                if (value =="") {
                    return { result: false, message: "Value should be not empty." };
                }
                return true;
            };
            $("#jqxGrid").bind('cellendedit', function (event) {
                try{
                    var args = event.args;
                    var column = args.datafield ,_row = args.rowindex,_value = args.value;
                    var _data=$("#jqxGrid").jqxGrid('getrowdata', _row);
                    var _id=_data._id;
                    if(_id==undefined || _id==""){
                        return;
                    }
                    switch(column){
                        case 'lang_set':
                            if(_value!=_data.lang_set)
                                backend_update('system','language','lang',_id,{'lang_set':_value});
                            break;
                        case 'lang_key':
                            if(_value!=_data.lang_key)
                                backend_update('system','language','lang',_id,{'lang_key':_value});
                            break;
                        case 'lang_text':
                            if(_value!=_data.lang_text)
                                backend_update('system','language','lang',_id,{'lang_text':_value});
                            break;
                        default:
                        uiMessage("Unkown this cell. Maybe 'editable' of this colums is 'off'."); 
                    }
                }catch(e){
                    uiMessage(e.message);
                }
            });
        }catch(e){}
    }
    function _detail(id){
        backendloading();
        $("#editor_box .content-biz").load(
        "/backend/system/lang_editor/" + id,
        function() {
                $("#lang_frm").validationEngine();
                bckdialog({
                    title:'Language',message:$('#editor_box')
                }).open();
                backendloaded();
            }
        );
    }
    
    function _save(){
        new backend({
            url         :   "/backend/system/lang_save",
            data        :   $('#lang_frm').serialize(),
            callback    :   function(data){
                if(data.result<0){
                    new bckdialog({type:'error'}).open(data.message);
                }else{
                    uiMessage(data.message);
                    $('#editor_box').dialog('close');
                    menu.Refresh();
                }
            }
        }).call();
        return false;
    }
    var grid_options,
        adatafiels  = <?=json_encode($datafields)?>,
        acolumns    = <?=json_encode($columns)?>,
        alistitems  = <?=json_encode($list)?>,
        jqxGrid;
    var bindingsource='<?=$bindingsource?>';
    $(document).ready(function(){
        initSetting();
        Grid({
            grid_opt:{
                filterable: false,showfilterrow: false,editable:true,editmode:'dblclick',
                selectionmode: 'singlecell'
            }
        }).init();
    });
</script>
<script src="/libraries/backend/backend.grid.default.js"></script>
<?php require "/../00_include/02_foot.php" ?>
